package cn.edu.gzhmt.order.domain;

import java.io.Serializable;
import java.math.BigDecimal;

import cn.edu.gzhmt.goods.domain.Goods;

/**
 * 订单明细表实体类（订单条目）
 * @author azhuo
 *
 */
public class OrderItem implements Serializable {

	private String iid; // 条目主键id
	private Integer count; // 条目商品数量
	private Goods goods; // 条目中的商品
	private String gid; // 商品的id，方便进行关联关系查询
	private Double subtotal; // 条目小计
	private Order order; // 条目所属的订单

	public String getIid() {
		return iid;
	}

	public void setIid(String iid) {
		this.iid = iid;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public String getGid() {
		return gid;
	}

	public void setGid(String gid) {
		this.gid = gid;
	}

	public Double getSubtotal() {
		/*if (subtotal == null || subtotal == 0) {
			BigDecimal num = new BigDecimal(this.count + "");
			BigDecimal price = new BigDecimal(this.goods.getPrice() + "");
			subtotal = num.multiply(price).doubleValue();
		}
		return subtotal;*/

		if (subtotal == null || subtotal == 0.0) {
			subtotal = count * this.goods.getPrice();
		}
		return subtotal;

	}

	public void setSubtotal(Double subtotal) {
		this.subtotal = subtotal;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@Override
	public String toString() {
		/*return "OrderItem [iid=" + iid + ", count=" + count + ", goods="
				+ goods + ", gid=" + gid + ", subtotal=" + subtotal
				+ ", order=" + order + "]";*/
		return "OrderItem [iid=" + iid + ", count=" + count + ", goods="
				+ goods + ", gid=" + gid + ", subtotal=" + subtotal + "]";
	}

}
